<?php
$activity = $this->getCollection();
?>

<div class="entry-edit">
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend">活动基本信息</h4>
        <div class="form-buttons"></div>
    </div>
    <div class="fieldset  ignore-validate" id="coupons_information_fieldset">
        <div class="hor-scroll">
            <table cellspacing="0" class="form-list">
                <tbody>
                <tr>
                    <td class="label" style="text-align: right;"><label for="name">活动名称<span class="required">*</span></label></td>
                    <td class="value">
                        <?php if($activity && $activity->getName()): ?>
                            <input id="name" name="name" value="<?php echo $activity->getName(); ?>" title="活动内容" class="required-entry input-text"  type="text">
                        <?php else: ?>
                            <input id="name" name="name"  title="活动内容" class="required-entry input-text"  type="text">
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="value">
                        <?php if($activity && $activity->getAdminId()): ?>
                            <input name="id" value="<?php echo $activity->getId(); ?>" class="required-entry input-text"  type="hidden">
                        <?php endif; ?>
                    <td class="value">
                        <?php if($activity && $activity->getAdminId()): ?>
                            <input name="admin_id" value="<?php echo $activity->getAdminId(); ?>" class="required-entry input-text"  type="hidden">
                        <?php else: ?>
                            <input name="admin_id" class="required-entry input-text" value="<?php echo Mage::getSingleton('admin/session')->getUser()->getUserId();?>" type="hidden">
                        <?php endif; ?>
                    </td>
                </tr>

                <tr>
                    <td class="label" style="text-align: right;"><label for="status">状态<span class="required">*</span></label></td>
                    <td class="value">
                        <select id="status" name="status" class="required-entry select">
                        <?php if($activity): ?>
                                <?php if($activity->getStatus()): ?>
                                <option value="1"  selected="selected">启用</option>
                                <option value="0">禁用</option>
                            <?php else: ?>
                                <option value="1">启用</option>
                                <option value="0"  selected="selected">禁用</option>
                            <?php endif;?>
                        <?php else: ?>
                                <option value="1">启用</option>
                                <option value="0">禁用</option>
                        <?php endif; ?>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td class="label" style="text-align: right;"><label for="website_id">站点<span class="required">*</span></label></td>
                    <td class="value">
                        <?php $websites = Mage::getModel('core/website')->getCollection()->toOptionHash();?>
                        <?php $websiteId =Mage::getSingleton('admin/session')->getUser()->getWebsiteId();?>
                        <select id="website_id" name="website_id" class="required-entry select">
                            <?php if($activity && $activity->getWebsiteId()): ?>
                                <option value="<?php echo $activity->getWebsiteId(); ?>"><?php echo $websites[$activity->getWebsiteId()]; ?></option>
                            <?php elseif($websiteId): ?>
                                <option value="<?php echo $websiteId; ?>"><?php echo $websites[$websiteId]; ?></option>
                            <?php else: ?>
                            <?php foreach ($websites as $key => $website):?>
                                <option value="<?php echo $key ?>"><?php echo $website; ?></option>
                            <?php endforeach; ?>
                        </select>
                    <?php endif; ?>
                    </td>
                </tr>

                <tr>
                    <td class="label" style="text-align: right;"><label for="start_at">开始时间<span class="required">*</span></label></td>
                    <td class="value">
                        <?php if($activity && $activity->getStartAt()): ?>
                        <input id="start_at" class=" input-text" type="text" value="<?php echo $activity->getStartAt(); ?>" name="start_at">
                        <img id="start_at_trig" class="v-middle" style="" title="Select Date" alt="" src="<?php echo $this->getSkinUrl('images/grid-cal.gif')?>">
                        <?php else: ?>
                            <input id="start_at" class=" input-text" type="text" value="" name="start_at">
                            <img id="start_at_trig" class="v-middle" style="" title="Select Date" alt="" src="<?php echo $this->getSkinUrl('images/grid-cal.gif')?>">
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="label" style="text-align: right;"><label for="end_at">结束时间<span class="required">*</span></label></td>
                    <td class="value">
                        <?php if($activity && $activity->getEndAt()): ?>
                            <input id="end_at" class=" input-text" type="text" value="<?php echo $activity->getEndAt(); ?>" name="end_at">
                            <img id="end_at_trig" class="v-middle" style="" title="Select Date" alt="" src="<?php echo $this->getSkinUrl('images/grid-cal.gif')?>">
                        <?php else: ?>
                            <input id="end_at" class=" input-text" type="text" value="<?php echo $activity->getEndAt(); ?>" name="end_at">
                            <img id="end_at_trig" class="v-middle" style="" title="Select Date" alt="" src="<?php echo $this->getSkinUrl('images/grid-cal.gif')?>">
                        <?php endif; ?>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="entry-edit" id="wrap" >
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend">模板选择</h4>
        <div class="form-buttons"></div>
    </div>
    <div class="fieldset  ignore-validate" id="coupons_information_fieldset">
        <div class="hor-scroll">
            <table cellspacing="0" class="form-list">
                <tr>
                    <td class="label" style="text-align: right;"><label for="name">活动模板<span class="required">*</span></label></td>
                    <td class="value">
                        <select name="template_id" id="template_id">
                            <option data-url="" value="">请选择模板</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/1.jpg');?>" value="1">五一模板--PC版</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/2.jpg');?>"value="2">五一模板--移动版</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/3.jpg');?>" value="3">端午模板--PC版</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/4.jpg');?>" value="4">端午模板--移动版</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/5.jpg');?>" value="5">中秋模板--PC版</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/6.jpg');?>" value="6">中秋模板--移动版</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/7.jpg');?>" value="7">国庆模板--PC版</option>
                            <option data-url="<?php echo $this->getSkinUrl('pms/images/8.jpg');?>" value="8">国庆模板--移动版</option>
                        </select>
                        <?php
                        if($activity->getTemplateId()){
                            echo '<script type="text/javascript">';
                            echo "document.getElementById('template_id').value = ".$activity->getTemplateId();
                            echo '</script>';
                        }
                        ?>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div id="templateimgs" style="width: 600px;height;700px;display: none;"><img id="templateimg" alt="" style="width: 100%;height: 100%;"></div>
<script type="text/javascript">
    //<![CDATA[
    Calendar.setup({
        inputField: "start_at",
        ifFormat: "%Y-%m-%e %H:%M:%S",
        showsTime: true,
        button: "start_at_trig",
        align: "Bl",
        singleClick : true
    });
    //]]>
</script>
<script type="text/javascript">
    //<![CDATA[
    Calendar.setup({
        inputField: "end_at",
        ifFormat: "%Y-%m-%e %H:%M:%S",
        showsTime: true,
        button: "end_at_trig",
        align: "Bl",
        singleClick : true
    });
    //]]>
</script>
<script type="text/javascript">
    var  $j = jQuery.noConflict();
    //Template Form Validation
    function saveAndContinueEdit(){
        var name = $j("#name").val();
        var status = $j("#status").val();
        var websiteid = $j("#website_id").val();
        var startat = $j("#start_at").val();
        var endat = $j("#end_at").val();
        var templateid = $j("#template_id").val();
        if(name =="" || status =="" || startat == "" ||websiteid=="" || endat == "" || templateid==""||websiteid == "0"){
            layer.alert("带*号的都是必填项，请完善活动信息！");
            return false;
        }
        editForm.submit();
    }

    //select templateid view img
    $j("#template_id").change(function(){
       var im=$j(this).find ("option:selected").attr ("data-url");
        if(im){
            $j("#templateimgs").show();
            $j('#templateimg').attr('src',im);
        }else{
            $j("#templateimgs").hide();
        }
    })

</script>
